#include "timemanager.h"

TimeManager* TimeManager::s_instance = nullptr;

TimeManager::TimeManager(QObject *parent) : QObject(parent) {
    m_timer = new QTimer(this);
    connect(m_timer, &QTimer::timeout, this, [this]() {
        // 发送默认格式（年月日 时分秒）
        emit timeUpdated(currentTimeString());
        // 发送仅时分秒格式（HH:mm:ss）
        emit timeUpdatedHMS(currentTimeString("HH:mm:ss"));
    });
    m_timer->start(1000);  // 每秒更新一次
}

TimeManager* TimeManager::instance() {
    if (!s_instance) {
        s_instance = new TimeManager();
    }
    return s_instance;
}

QString TimeManager::currentTimeString(const QString &format) const {
    return QDateTime::currentDateTime().toString(format);
}
